#include<bits/stdc++.h>
#define db double
using namespace std;
const int N=2e6+5,mod=1e9+7;
int n;
int a[N],b[N],sum;
vector<int> vec;
map<vector<int>,int> ma;
void dfs(int x,int p1,int p2) {
    if(x==2*n-1) {
        sum+=(!ma[vec]);
        ma[vec]++;
        return ;
    }
    if(p1<n) {
        vec.push_back(b[p2]);
        dfs(x+1,p1+1,p2);
        vec.pop_back();
    }
    if(p2<n) {
        vec.push_back(a[p1]);
        dfs(x+1,p1,p2+1);
        vec.pop_back(); 
    }
}
int main() {
    freopen("zha.in","r",stdin);
    freopen("zha.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++) scanf("%d",&b[i]);
    dfs(1,1,1);
    printf("%d\n",sum%mod);
    return 0;
}
/*
5
3 1 4 2 5
3 2 4 1 5
*/
